package cn.tedu.service;


import cn.tedu.dao.ProviderMapper;
import cn.tedu.pojo.Provider;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ProviderServiceImpl implements ProviderService {
    // 导入持久层
    //持久层只有接口，所以无须导入
    @Autowired
    private ProviderMapper providerMapper;

    /**
     *
     * @param proName
     * @param proCode
     * @param currentPage
     * @param pageSize
     * @return 页面设定信息
     */
    @Override
    public PageInfo<Provider> getList(String proName, String proCode, Integer currentPage, Integer pageSize) {
        // PageHelper.startPage()在SQL上进行了分页,相当于在之后语句上加入分页SQL语句。
        PageHelper.startPage(currentPage,pageSize);
        List<Provider> list = providerMapper.getList(proName,proCode);
        PageInfo<Provider> pageInfo = new PageInfo<Provider>(list);
        return pageInfo;
    }

    @Override
    public boolean add(Provider provider) {
        return providerMapper.add(provider) > 0;
    }

    @Override
    public boolean modify(Provider provider) {
        return providerMapper.modify(provider)>0;
    }

    @Override
    public boolean delete(Integer id) {
        return providerMapper.delete(id) >0;
    }

    @Override
    public Provider getById(Integer id) {
        return providerMapper.getById(id);
    }
}